package com.itmyx.base.util.log;

import org.apache.ibatis.session.SqlSessionFactory;
import com.itmyx.base.util.data.ParamData;
import com.itmyx.base.util.file.PropertiesUtils;

/**
 * 显示sql的工具类
 * @author itmyx
 *
 */
public class ShowSqlUtil {
	
	private static final Logger logger = Logger.getLogger(Logger.class);
	
	/**
	 * 显示mybatis执行sql
	 */
	public static void showMybatisSql(SqlSessionFactory sqlSessionFactory,String nameSpace,String methodName,ParamData param){
		String showSql = PropertiesUtils.getValue("/variable/config.properties", "showSql");
		if("true".equals(showSql)){
			String sql = sqlSessionFactory.getConfiguration().getMappedStatement(nameSpace+"."+methodName).getBoundSql(param).getSql();
			logger.info("执行"+methodName+"开始:=======================>");
			logger.info(sql);
			logger.info("执行"+methodName+"结束:=======================>");
		}
	}

}
